package cn.dceast.former.controller;

import cn.dceast.common.data.RtnData;
import cn.dceast.former.model.EyeModelComment;
import cn.dceast.former.service.EyeModelCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by fanbo on 2017-07-22.
 * 模型评价详情
 */
@Controller
@RequestMapping("/eyeModelEvaluateController")
@Api(tags = {"eyeModelEvaluateController"})
public class EyeModelEvaluateController {

    public static final Logger logger = LoggerFactory.getLogger(EyeModelEvaluateController.class);

    @Autowired
    private EyeModelCommentService eyeModelCommentService;


    /**
     * 根据模型ID查询评论信息
     * @param userID
     * @param modelID
     * @return
     */
    @ApiOperation(value = "查询模型评论", notes = "查询模型评论")
    @RequestMapping(value = "/getModelEvaluate.do", method = RequestMethod.GET)
    @ResponseBody
    public RtnData selectModelEvaluate(@RequestParam(required = true) String userID,
                                       @RequestParam(required = true) String modelID){
        EyeModelComment eyeModelEvaluate = new EyeModelComment();
        eyeModelEvaluate.setEvaluateUser(userID);
        eyeModelEvaluate.setModelId(Integer.parseInt(modelID));
        Map<String,Object> restMap = new HashMap<>();
        try {

            List<Map<String,Object>> modelEvaluateList = eyeModelCommentService.selectModelEvaluateById(userID,Integer.parseInt(modelID));
            restMap.put("list",modelEvaluateList);
            return RtnData.ok(restMap);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("查询评论失败");
            return RtnData.fail("查询评论失败！");
        }
    }
}
